package com.zx.idc.backend.gui.api.commom.factory;

import com.zx.idc.common.spring.SpringConfigUtil;
import com.zx.idc.xml.entity.Return;
import com.zx.idc.xml.utils.JaxbUtils;

import java.time.LocalDateTime;

import static com.zx.idc.common.attributes.SystemAttributes.WEB_SERVICE_VERSION;
import static com.zx.idc.common.attributes.WebServiceReturnCodeAttributes.*;

/**
 * Created by hasee on 2019/2/21.
 */
public class ReturnFactory {

    private static final String v;

    static {
        v = SpringConfigUtil.get(WEB_SERVICE_VERSION);
    }

    /**
     * 解密失败
     *
     * @param msg
     * @return
     */
    public static String getDecryptionFailedReturn(String msg) {
        return return2String(newReturn(msg, FILE_DECRYPTION_FAILED));
    }

    /**
     * 成功
     *
     * @param msg
     * @return
     */
    public static String getOKReturn(String msg) {
        return return2String(newReturn(msg, OK));
    }

    /**
     * 验证失败
     *
     * @param msg
     * @return
     */
    public static String getVerificationFailedReturn(String msg) {
        return return2String(newReturn(msg, FILE_VERIFICATION_FAILED));
    }

    /**
     * 格式异常
     *
     * @param msg
     * @return
     */
    public static String getFormatExceptionReturn(String msg) {
        return return2String(newReturn(msg, FILE_FORMAT_EXCEPTION));
    }

    /**
     * 内容异常
     *
     * @param msg
     * @return
     */
    public static String getContextExceptionReturn(String msg) {
        return return2String(newReturn(msg, FILE_CONTEXT_EXCEPTION));
    }

    /**
     * 其他异常
     *
     * @param msg
     * @return
     */
    public static String getOtherExceptionReturn(String msg) {
        return return2String(newReturn(msg, OTHER_EXCEPTION));
    }

    /**
     * 解压缩异常
     *
     * @param msg
     * @return
     */
    public static String getDecompressionFailedReturn(String msg) {
        return return2String(newReturn(msg, FILE_DECOMPRESSION_FAILED));
    }

    /**
     * 版本兼容异常
     *
     * @param msg
     * @return
     */
    public static String getVersionCompatibilityReturn(String msg) {
        return return2String(newReturn(msg, FILE_DECOMPRESSION_FAILED));
    }

    public static String return2String(Return aReturn) {
        return JaxbUtils.beanToXml(aReturn);
    }

    private static Return newReturn(String msg, Integer resultCode) {
        return new Return()
            .setMsg(msg)
            .setResultCode(resultCode);
    }

}
